package org.edu.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "SCIENCY", catalog = "SCHOOL")
public class Sciency implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long sciency_id;
	private Set<User> users = new HashSet<>();
	private Set<Lesson> lessons = new HashSet<>();
	private Faculity faculity;
	private String sciency_code;
	private String sciency_name;

	@Id
	@GeneratedValue
	@Column(name = "SCIENCY_ID")
	public Long getSciency_id() {
		return sciency_id;
	}

	public void setSciency_id(Long sciency_id) {
		this.sciency_id = sciency_id;
	}

	@OneToMany(targetEntity = User.class, mappedBy = "sciency", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	@OneToMany(targetEntity = Lesson.class, mappedBy = "sciencyL", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<Lesson> getLessons() {
		return lessons;
	}

	public void setLessons(Set<Lesson> lessons) {
		this.lessons = lessons;
	}

	@ManyToOne
	@JoinColumn(name = "FACULITY_ID")
	public Faculity getFaculity() {
		return faculity;
	}

	public void setFaculity(Faculity faculity) {
		this.faculity = faculity;
	}

	@Column(name = "SCIENCY_CODE")
	public String getSciency_code() {
		return sciency_code;
	}

	public void setSciency_code(String sciency_code) {
		this.sciency_code = sciency_code;
	}

	@Column(name = "SCIENCY_NAME")
	public String getSciency_name() {
		return sciency_name;
	}

	public void setSciency_name(String sciency_name) {
		this.sciency_name = sciency_name;
	}

	public Sciency() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((sciency_code == null) ? 0 : sciency_code.hashCode());
		result = prime * result
				+ ((sciency_id == null) ? 0 : sciency_id.hashCode());
		result = prime * result
				+ ((sciency_name == null) ? 0 : sciency_name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Sciency other = (Sciency) obj;
		if (sciency_code == null) {
			if (other.sciency_code != null)
				return false;
		} else if (!sciency_code.equals(other.sciency_code))
			return false;
		if (sciency_id == null) {
			if (other.sciency_id != null)
				return false;
		} else if (!sciency_id.equals(other.sciency_id))
			return false;
		if (sciency_name == null) {
			if (other.sciency_name != null)
				return false;
		} else if (!sciency_name.equals(other.sciency_name))
			return false;
		return true;
	}

}
